package com.dzm.service.impl;

import com.dzm.constant.RedisConstant;
import com.dzm.entity.Dept;
import com.dzm.mapper.DeptMapper;
import com.dzm.service.IDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Dzm
 * @since 2024-08-17
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public List<Dept> findAllDept() {
        List<Dept> list = (List<Dept>) redisTemplate.opsForValue().get(RedisConstant.REDIS_DEPT);
        if(list == null || list.size() == 0) {
            list = this.list();
            redisTemplate.opsForValue().set(RedisConstant.REDIS_DEPT, list, 1, TimeUnit.DAYS);
        }

        return list;
    }
}
